package br.com.moxirpt.model.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Banco {
	
	// Conexao SERVIDOR
	private String senha = "moxi";
	private String usuario = "moxi";	
	private String url = "jdbc:postgresql://localhost:5432/moxi"; 
	//private String url = "jdbc:postgresql://192.168.1.1:5432/moxi";
	private String driver = "org.postgresql.Driver";
	
	
	public Banco() throws SQLException, ClassNotFoundException {
		Class.forName(driver);

	}
	
	public static int numConexoesAbertas = 0;
	
	public Connection conecta() throws SQLException {
		numConexoesAbertas++;
		//System.err.println("## Conectou: "+numConexoesAbertas);
		return DriverManager.getConnection(url, usuario, senha);
	}

	public void desconecta(Connection conn) throws SQLException {
		numConexoesAbertas--;
		//System.err.println("## Fechou: "+numConexoesAbertas);
		conn.close();
	}

	public String getDriver() {
		return driver;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUsuario() {
		return usuario;
	}

	public void setUsuario(String usuario) {
		this.usuario = usuario;
	}
}
